package com.udata.server.servlet;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.udata.server.util.JsonBeautifyUtil;

public class JsonBeautifyServlet extends AbstractServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6133599877684458113L;

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String payloadRequest = this.getBody(req);
		HashMap<String, String> parameterMap = getParameterMap(payloadRequest);

		String action = parameterMap.get("action");
		if (action.equals("beautify")) {
			String content = parameterMap.get("content");

			try {
				String json = JsonBeautifyUtil.beautifyJson(content);
				this.sendResponseMsg(resp, json);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

}
